﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Business.CleanChina;
using Torch.WL.Entity.CleanChina;

namespace Torch.WL.Business
{
    public class MagazineProvider : BaseProvider<MagazineProvider.RequestDataInfo>, IDataProvider
    {
        public MagazineProvider(string _jsonInfo): base(_jsonInfo)
        {

        }

        public IMessageInfo Do()
        {
            IMessageInfo message = new MessageInfo();
            message.code = (int)MessageCodeType.Success;
            message.message = Utils.GetEnumDescription(MessageCodeType.Success);
            message.data = ProcessResponseData();

            return message;
            
        }

        private ResponseDataInfo ProcessResponseData()
        {
            //use postdata.data to process responseData

            if (postdata == null || postdata.data == null)
            {
                message.code = (int)MessageCodeType.WrongRequestPara;
                message.message = Utils.GetEnumDescription(MessageCodeType.WrongRequestPara);
                return null;
            }

            ResponseDataInfo responseData = new ResponseDataInfo();

            TbEMEntity entity = TbEMManager.Instance().GetModelByCache(postdata.data.magazine_id);

            if (entity == null)
                return null;

            List<string> imglist = new List<string>();

            entity.imagelist.ForEach(delegate(string imgname){
                    imglist.Add(ConfigHelper.GetConfigString("WebsiteImageUrl")+imgname);
                });
            
            responseData.images = imglist;
            return responseData;

         
        }

        public class RequestDataInfo 
        {
            public int magazine_id { get; set; }
        }

        public class ResponseDataInfo
        {
            public List<string> images { get; set; }

        }


    }
}
